#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.conf import settings
from django.utils.deprecation import MiddlewareMixin

from utils.MyJsonResponse import errorDaemon


class DaemonMiddleware(MiddlewareMixin):

    def process_response(self, request, response):
        print("process_response")
        daemonKey = getattr(settings, 'SERVER_DAEMON_KEY')
        inDaemonKey=request.GET.get('daemonKey')
        if inDaemonKey is None:
            return errorDaemon("参数daemonKey不存在")
        if daemonKey != inDaemonKey:
            return errorDaemon("daemonKey验证失败")

        print(daemonKey)
        return response
